package com.example.linyiquan.application.util;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.example.linyiquan.application.beam.AppBeam;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by linyiquan on 17-4-20.
 */

public class Utils {

    public static List<AppBeam> getApps(Context context){
        List<AppBeam> list=new ArrayList<>();
        PackageManager pm=context.getPackageManager();
        List<PackageInfo> pack=pm.getInstalledPackages(0);
        for (PackageInfo pi:pack){
            if((pi.applicationInfo.flags& ApplicationInfo.FLAG_SYSTEM)==0&&
                    (pi.applicationInfo.flags&ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)==0){
                AppBeam item=new AppBeam();
                item.setAppname(pi.applicationInfo.loadLabel(pm).toString());
                item.setAppicon(pi.applicationInfo.loadIcon(pm));
                item.setPackageInfo(pi.applicationInfo.packageName);
                list.add(item);
            }
        }
        return list;
    }

}
